/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 *
 * web http://sixrevisions.com/tutorials/javascript_tutorial/create-a-slick-and-accessible-slideshow-using-jquery/
 */
(function($){
$(document).ready(function(){
  var currentPositionV = 0;
  var slideWidthV = 200;
  var slidesV = $('.slideVideo');
  var numberOfSlidesV = slidesV.length;

  // Remove scrollbar in JS
  $('#slidesContainerVideo').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slidesV
  .wrapAll('<div id="slideInnerVideo"></div>')
  // Float left to display horizontally, readjust .slides width
  .css({
    'float' : 'left',
    'width' : slideWidthV
  });

  // Set #slideInner width equal to total width of all slides
  $('#slideInnerVideo').css('width', slideWidthV * numberOfSlidesV);

  // Insert left and right arrow controls in the DOM
  $('#slideshowVideo')
    .prepend('<span class="controlVideo" id="leftControlVideo">Move left</span')
    .append('<span class="controlVideo" id="rightControlVideo">Move right</span');

  // Hide left arrow control on first load
  manageControls(currentPositionV);

  // Create event listeners for .controls clicks
  $('.controlVideo')
    .bind('click', function(){
    // Determine new position
      currentPositionV = ($(this).attr('id')=='rightControlVideo')
    ? currentPositionV+1 : currentPositionV-1;

      // Hide / show controls
      manageControls(currentPositionV);
      // Move slideInner using margin-left
      $('#slideInnerVideo').animate({
        'marginLeft' : slideWidthV*(-currentPositionV)
      });
    });

  // manageControls: Hides and shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
    if(position==0){ $('#leftControlVideo').hide() }
    else{ $('#leftControlVideo').show() }
    // Hide right arrow if position is last slide
    if(position==numberOfSlidesV-1){ $('#rightControlVideo').hide() }
    else{ $('#rightControlVideo').show() }
    }
  });
})(jQuery);

